﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BaseData.ReadAPI.Controllers
{
    /// <summary>
    /// 文件上传控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UpLoadController : ControllerBase
    {

        /// <summary>
        /// 上传图片
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpImg()
        {
            var file = Request.Form.Files[0];//获取第一个上传的文件
            var path = Directory.GetCurrentDirectory() + "/Imgs/"+file.FileName;//构造目标路径
            using (FileStream fs = System.IO.File.Create(path))// 创建文件流
            {
                file.CopyTo(fs); //将上传的文件复制到目标路径
                fs.Close();//关闭流
            }
            return Ok("http://localhost:5139/Imgs/"+file.FileName);
        }
    }
}
